﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BaseUi : MonoBehaviour
{
    public RectTransform rt
    {
        get {
            return GetComponent<RectTransform>();
        }
    }
    protected void removeAllChildren ()
	{
        int childCount = transform.childCount;
		for (int i = 0; i < childCount ; i++) {
			Destroy (transform.GetChild (0).gameObject);
		}
	}
    public T loadUi<T>(string model, string ui, Transform parent) where T : BaseUi
    {
        GameObject prefab = Resources.Load<GameObject>("ui/" + model + "/" + ui);
        GameObject obj = Instantiate(prefab);
        obj.transform.SetParent(parent);        
        obj.GetComponent<RectTransform>().localScale = Vector2.one;
        return obj.GetComponent<T>();
    }
}
